package com.itheima.service;

import com.itheima.dao.UserMapper2;
import com.itheima.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class UserServiceTest {
    public static void main(String[] args) throws IOException {
        //获取核心配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        //获得session工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //获得session会话对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //自动获取dao层实现类
        UserMapper2 mapper = sqlSession.getMapper(UserMapper2.class);
        List<User> userList = mapper.findAll();
        System.out.println(userList);
        //释放资源
        sqlSession.close();
    }
}
